package me.example.eureka;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author HZQ
 * @date 2018/3/1
 * @copyright sankuai.com
 */
@RestController
public class TestController {

    @Autowired
    private DiscoveryClient client;

    @RequestMapping(value = "/hello/{username}", method = RequestMethod.GET)
    public String hello(@PathVariable("username") String username) {
        ServiceInstance instance = client.getLocalServiceInstance();
        //输出服务相关的信息
        System.out.println("host is:" + instance.getHost());
        System.out.println("port is:" + instance.getPort());
        System.out.println("ServiceID is:" + instance.getServiceId());
        //返回字符串
        return "hello " + username;
    }
}
